<template>
  <n-data-table
    :columns="columns"
    :data="tableData"
    :pagination="false"
    :bordered="false"
  />
</template>
<script setup lang="ts">
import { ref, h } from 'vue'
import { NDataTable } from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
import userApi from '@/service/api/user'
const router = useRouter()
const tableData = ref([])
const init = async () => {
  const { data } = await userApi.revenueLog({
    current: 1,
    size: 10
  })
  tableData.value = data
}
init()
const columns: DataTableColumns<any> = [
  {
    title: '标题',
    key: 'content',
    render(row: any) {
      if (row.type === 'BUY_PHOTO') {
        return h(
          'div',
          {
            class: 'cursor-pointer',
            onClick: () => {
              router.push({
                path: '/detail',
                query: {
                  id: row.photoInfo.id
                }
              })
            }
          },
          `出售[${row.photoInfo.name}]`
        )
      } else {
        return h('div', {}, row.content)
      }
    }
  },
  {
    title: '价格',
    key: 'integral',
    render(row: any) {
      return h('div', {}, row.integral === 0 ? '免费' : `${row.integral}软妹币`)
    }
  },
  {
    title: '订单号',
    key: 'id'
  },
  {
    title: '时间',
    key: 'create_at'
  }
]
</script>

<style scoped lang="scss"></style>
